/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author Felipe
 */
public class Encriptador
{
    public static String encriptar(String pass)
    {
        try 
        {
            MessageDigest md;
            md = MessageDigest.getInstance("MD5");
            
            byte[] passBytes = pass.getBytes();
            
            md.reset();
            
            byte[] digested = md.digest(passBytes);
            StringBuffer sb = new StringBuffer();
            
            for(int i=0;i<digested.length;i++)
                sb.append(Integer.toHexString(0xff & digested[i]));
            
            return sb.toString();
        } 
        catch (NoSuchAlgorithmException ex) 
        {
            ex.printStackTrace();
            return pass;
        }
   }
    
    public static boolean check (String clave, String encriptada)
    {
        return encriptar(clave).equals(encriptada);
    }
}